import React, {useEffect, useState} from 'react';
import styles from './style.less';
import {queryIssueVersion, queryLicense} from "@/pages/sys/reg/service";

const License = () => {
  const [licInfo, setLicInfo] = useState({orgName: '', prodName: '', edition: '', version: ''});
  const [licEnum, setLicEnum] = useState([]);

  useEffect(async () => {
    const res = await queryLicense();
    if (res?.data) {
      setLicInfo(res.data);
    }
  }, []);

  useEffect(async () => {
    const res = await queryIssueVersion();
    if (res?.data) {

      setLicEnum(res.data);
    }
  }, []);

  const editionLabel = (en, e) => {
    const curLabel = en.map(item => {
      if (item.value === e) {
        return item.label;
      }
      return '';
    });
    return curLabel?? '';
  };

  return (
    <div className={styles.main}>
      <div className={styles.desc}>
        <ul>
          <li><label>产品名称</label>：{licInfo.prodName}</li>
          <li><label>授权组织</label>：{licInfo.orgName}</li>
          <li><label>版 本</label>：{editionLabel(licEnum, licInfo.edition)}</li>
          <li><label>版 本 号</label>：{licInfo.version}</li>
          {licInfo.edition && licInfo.edition !== 'Free' && (<li><label>到期时间</label>：{licInfo.expiryTime}</li>)}
        </ul>
      </div>
    </div>
  );
};

export default License;
